<template>
  <div class="baidu-map-container">
    <div class="map-header">
      <span class="address-text">{{ doctorAddress }}</span>
      <i class="location-icon">📍</i>
    </div>
    <div class="map-wrapper" ref="mapContainer">
      <div class="map-placeholder">
        <div class="loading-animation">
          <div class="loading-dot"></div>
          <div class="loading-dot"></div>
          <div class="loading-dot"></div>
        </div>
        <p class="loading-text">正在加载地图...</p>
      </div>
    </div>
    <div class="map-actions">
      <button class="map-btn" @click="openInBaiduMap">在百度地图中打开</button>
      <button class="map-btn" @click="getDirections">导航</button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, nextTick } from 'vue'

interface Props {
  doctorAddress: string
}

const props = defineProps<Props>()
const mapContainer = ref<HTMLElement>()

// 模拟地图加载动画
onMounted(async () => {
  await nextTick()
  
  // 模拟地图加载过程
  setTimeout(() => {
    if (mapContainer.value) {
      mapContainer.value.innerHTML = `
        <div class="map-content">
          <div class="map-mock">
            <div class="map-pin">
              <div class="pin-icon">📍</div>
              <div class="pin-pulse"></div>
            </div>
            <div class="map-streets">
              <div class="street street-1"></div>
              <div class="street street-2"></div>
              <div class="street street-3"></div>
            </div>
            <div class="map-buildings">
              <div class="building building-1"></div>
              <div class="building building-2"></div>
              <div class="building building-3"></div>
            </div>
          </div>
        </div>
      `
    }
  }, 2000)
})

// 在百度地图中打开
const openInBaiduMap = () => {
  const encodedAddress = encodeURIComponent(props.doctorAddress)
  window.open(`https://map.baidu.com/?q=${encodedAddress}`, '_blank')
}

// 获取导航
const getDirections = () => {
  const encodedAddress = encodeURIComponent(props.doctorAddress)
  window.open(`https://map.baidu.com/?q=${encodedAddress}&mode=driving`, '_blank')
}
</script>

<style scoped>
.baidu-map-container {
  background-color: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin: 8px 0;
}

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.address-text {
  font-size: 14px;
  color: #333;
  flex: 1;
}

.location-icon {
  font-size: 16px;
  margin-left: 8px;
}

.map-wrapper {
  height: 50px;
  background-color: #f5f5f5;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.map-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
}

.loading-animation {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.loading-dot {
  width: 8px;
  height: 8px;
  background-color: #1976d2;
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite both;
}

.loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.loading-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.loading-text {
  color: #666;
  font-size: 14px;
  margin: 0;
}

.map-content {
  height: 100%;
  position: relative;
}

.map-mock {
  height: 100%;
  background: linear-gradient(135deg, #e8f5e8 0%, #f0f8ff 100%);
  position: relative;
  overflow: hidden;
}

.map-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.pin-icon {
  font-size: 24px;
  animation: pulse 2s infinite;
}

.pin-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 2px solid #ff4444;
  border-radius: 50%;
  animation: ripple 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes ripple {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(2);
    opacity: 0;
  }
}

.map-streets {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.street {
  position: absolute;
  background-color: #ccc;
  opacity: 0.6;
}

.street-1 {
  top: 30%;
  left: 0;
  right: 0;
  height: 2px;
  animation: streetFlow 3s linear infinite;
}

.street-2 {
  top: 0;
  bottom: 0;
  left: 30%;
  width: 2px;
  animation: streetFlow 3s linear infinite reverse;
}

.street-3 {
  top: 70%;
  left: 0;
  right: 0;
  height: 1px;
  animation: streetFlow 4s linear infinite;
}

@keyframes streetFlow {
  0% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    opacity: 0.3;
  }
}

.map-buildings {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.building {
  position: absolute;
  background: linear-gradient(180deg, #ddd 0%, #bbb 100%);
  border-radius: 2px;
}

.building-1 {
  top: 20%;
  left: 20%;
  width: 30px;
  height: 60px;
  animation: buildingGlow 4s ease-in-out infinite;
}

.building-2 {
  top: 40%;
  right: 20%;
  width: 25px;
  height: 80px;
  animation: buildingGlow 4s ease-in-out infinite 1s;
}

.building-3 {
  bottom: 20%;
  left: 60%;
  width: 35px;
  height: 50px;
  animation: buildingGlow 4s ease-in-out infinite 2s;
}

@keyframes buildingGlow {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.05);
  }
}

.map-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.map-btn {
  flex: 1;
  padding: 8px 12px;
  background-color: #1976d2;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.map-btn:hover {
  background-color: #1565c0;
  transform: translateY(-1px);
}

.map-btn:active {
  transform: translateY(0);
}
</style>
